/////////////////////////科学计数法char* scientific_h(double value, int precision)舍入方式四舍五入，不用自研科学计数法用原来的E+000三位RTKLIB不可以正常运行，如果想还原的话代码在///
///"D:\HC\VScodezhengyang\GNSS3_decode software_obs&nav\src\dateconvert_old"//自带科学计数法输出函数
///"D:\HC\VScodezhengyang\GNSS3_decode software_obs&nav\src\dateconvert_new"//HC科学计数法输出函数
#include "stdafx.h"
#include<stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include<cmath>
#include<ctime>

#include "Gpsstr.h"
#include "ephcheck.h"
#include "CRC_Check.h"
#include "timeref.h"
#include <iostream>
#include <filesystem>

#include "cstring"
#include <string>

using namespace std;


const int header_size = 7;
const int data_byte_size = 2;  //数据体长度占用两个字节
//const int GpsPrnNum = 36;
//const int BD2PrnNum = 36;
struct StructGpsEphmeris_LNav    GpsEphmeris_LNav[GpsPrnNum];
struct StructBD2Ephmeris     BD2Ephmeris_B1[BD2PrnNum];

struct StructGpsEphmeris_LNav   GpsTmpEphmeris_LNav[GpsPrnNum];
struct StructBD2Ephmeris        BD2TmpEphmeris_B1[BD2PrnNum];

struct StructGpsAlmData GpsAlm[36];        //历书数据
struct StructObsBuff databuff_obsbuffdata[36];
extern struct StructSOW format_timer(double A);
// 数据格式 ：自遥测帧，自定位帧，测量元素帧，导航电文帧

int main(int argc, char* argv[])
{
	Uint8 RcvHeader[4] =	{ 0xAA, 0x55, 0x11, 0xBB};
	Uint8 RcvID[2] =		{ 0x00, 0x10};
	Uint8 SelfInfoID =		0x06;
	Uint8 SelfPosID =		0x00;
	Uint8 ObsID =			0x01;
	Uint8 EphID =			0x03;
	Uint8 SMPosLen = 172;
	Uint32 SMObsLen = 721;

	Gnss3SelfInfo* SelfInfo;
	tailStruct* tailofSelfinfo;

	tailStruct* tailofSelfPos;
	
	//DMGNSS3obs_t* DMobs;
	tailStruct* tailofobs;
	GNSS3eph_t* eph;
	tailStruct* tailofeph;

	int ephnum;

	ifstream  infile;

	long long ByteLen = 0;
	long long length = 0;
	int bdtFlag = 0;
	
	if (argc > 3) {
		printf("input error!");
		exit(1);
	}
	else if (argc >= 2) {
		infile.open(argv[1]);
		cout << argv[1];
		if (argc == 3) {
			bdtFlag = (int)argv[2];
			cout << " bdtFlag = " << argv[2] << endl;
		}
		else cout << " bdtFlag = 0" << endl;
	}
	else {
		infile.open("third_tianping.txt");
		//infile.open("Data2.txt");
	}
	// 字节长度
	if (infile.is_open())
	{
		cout << "file is opened" << endl;
	}
	infile.seekg(0, ios::end);//句柄放在文件末尾
	length = infile.tellg();//返回当前句柄位置，即偏移文件初始位置距离
	ByteLen = CalcByteLen(length);
	printf("byte length of the file is %d\r\n", ByteLen);
	infile.seekg(0, ios::beg);//ios::beg); //句柄放在文件开头


	//for (int i = strlen(argv[1]) - 1; i >= 0; i--)
	//{
	//	if (argv[1][i] != '\\')
	//	{
	//		argv[1][i] = 0;
	//		
	//	}
	//	else
	//	{
	//		break;
	//	}
	//}
	//printf(argv[1]);
	//printf("\n");
	string a("");
	//string a(argv[1]);

	ofstream  info(a + "info.txt");
	ofstream  pos(a + "pos.txt");
	ofstream  obstL1;
	ofstream  obstL2;
	ofstream  obstB1;
	ofstream  obstB3;
	ofstream  ephStream;
	ofstream  obsStream;
	ofstream  infocrccheck(a + "infocrccheck.txt");
	ofstream  poscrccheck(a + "poscrccheck.txt");
	ofstream  obscrccheck(a + "obscrccheck.txt");
	ofstream  ephcrccheck(a + "ephcrccheck.txt");
	ofstream compareGPST(a + "compareGNSS_Time.txt");
	ofstream  abnormal_epoch("abnormal_epoch.txt");
	string ephFile;
	string obsFile;
	/* rcvbug process */
	ofstream  CHK_obstL1;
	ofstream  CHK_obstL2;
	ofstream  CHK_obstB1;
	ofstream  CHK_obstB3;
	ofstream  CHK_obsStream;

	/****************************************************************************************************************************************/
	/****************************************************************RINEX格式数据***********************************************************/
	/****************************************************************************************************************************************/
	////导航电文头部分
	////char dt[66];
	//time_t t = time(NULL);
	////ctime_s(dt, sizeof dt, &t);
	//tm local;
	//gmtime_s(&local, &t);

	//ephStream << setw(9) << "2.10"<< setw(11) << " "<< "N: GPS NAV DATA" << setw(25) << " "<< "RINEX VERSION / TYPE"<< endl;
	//ephStream << setw(20) << "GNSS_decode software" << setw(20) << "ZJU Micro-Satellite" << setw(4) << local.tm_year + 1900 << setw(2) << setfill('0') << ++local.tm_mon << setw(2) << setfill('0') << local.tm_mday << " "
	//	<< setw(2) << setfill('0') << local.tm_hour << setw(2) << setfill('0') << local.tm_min << setw(2) << setfill('0') << local.tm_sec << " UTC " << "PGM / RUN BY / DATE " << endl;
	////if (argc > 1)
	////	ephStream  << "data: " << setw(56) << argv[1] << "COMMENT             " << endl;
	//ephStream << setfill('\40') << setw(60) << " " << "END OF HEADER" << endl;

	////观测数据头部分
	//obsStream << setw(9) << "3.03" << setw(11) << " " << "OBSERVATION DARA" << setw(4) << " " << "G" << setw(19) << " " << "RINEX VERSION / TYPE" << endl;
	//obsStream << "G=GPS  R=GLONASS  E=GALILEO  S=GEO  C=BDS  M=MIXED" << setw(10) << " " << "COMMENT             " << endl;
	//obsStream << setiosflags(ios::left) << setw(60) << "name of antenna marker" << "MARKER NAME" << endl;
	//obsStream << setw(60) << "number of antenna marker" << "MARKER NUMBER" << endl;
	//obsStream << resetiosflags(ios::left) << setw(20) << "GNSS_decode software" << setw(20) << "ZJU Micro-Satellite" << setw(4) << local.tm_year + 1900 << setw(2) << setfill('0') << local.tm_mon << setw(2) << setfill('0') << local.tm_mday << " "
	//	<< setw(2) << setfill('0') << local.tm_hour << setw(2) << setfill('0') << local.tm_min << setw(2) << setfill('0') << local.tm_sec << " UTC " << "PGM / RUN BY / DATE " << setfill(' ') << endl;
	////obsStream << "data: " << setw(56) << path << "COMMENT             " << endl;
	//obsStream << setw(20) << "HC" << setw(20) << "ZJU Micro-Satellite" << setw(20) << " " << "OBSERVER / AGENCY" << endl;
	////obsStream << setw(20) << "ZJU GNSSReceiver" << setw(20) << "receiver type" << setw(20) << "receiver version" << "REC #  / TYPE / VERS" << endl;
	////obsStream << setw(20) << "antenna name" << setw(20) << "antenna type" << setw(20) << " " << "ANT #  / TYPE" << endl;
	////obsStream << setw(14) << "0.0000" << setw(14) << "0.0000" << setw(14) << "0.0000" << setw(18) << " " << "APPROX POSITION XYZ" << endl;
	////obsStream << setw(14) << "0.0000" << setw(14) << "0.0000" << setw(14) << "0.0000" << setw(18) << " " << "ANTENNA: DELTA H/E/N" << endl;
	//obsStream << "G    6 C1C C2C L1C L2C D1C D2C" << setw(30) << " " << "SYS / # / OBS TYPES" << endl;
	//obsStream << setfill('\40') << setw(60) << " " << "END OF HEADER" << endl << endl;

	int dayofYear;
	int timemark = 0;
	int PrintControlFlag = 0;
	int mode;// GPS:0;BD:1;MIX:2
	Uint64 GPS_TIME;
	Uint32 crc;
	Uint8 buffer[header_size];
	int i, datatemp;
	DWORD word_gps[10];
	double total_length = 0.0;
	DWORD TocBuf[GpsPrnNum + BD2PrnNum];
	double ephobs[6] = {0},ephobspast[6] = {0};
	double lam = 299792458.0 / 1.561098E9;
	obschannel_t satobs[4][BD2PrnNum] = {0}, satobspast[4][BD2PrnNum] = {0};
	gtime_t obstime = {0}, obstimepast = { 0 };

	for (i = 0; i < GpsPrnNum + BD2PrnNum; i++) TocBuf[i] = 0xFFFFFFFF;

	for (i = 0; i < header_size; i++)
	{
		infile >> hex >> datatemp;
		buffer[i] = datatemp;
		total_length++;
	}
	while (1)
	{
		if (buffer[0] == RcvHeader[0] && buffer[1] == RcvHeader[1] && buffer[2] == RcvHeader[2] && buffer[3] == RcvHeader[3] && (buffer[6] == SelfInfoID||buffer[6] == SelfPosID))
		{
			break;
		}
		else
		{
			infile >> hex >> datatemp;
			total_length++;
			for (i = 0; i < header_size - 1; i++)
			{
				buffer[i] = buffer[i + 1];
			}
			buffer[6] = datatemp;
		}

	}
	while (!infile.eof())
	{
		int j;

		int flag_SelfInfo = 0;
		int flag_SelfPos = 0;
		int flag_obs = 0;
		int flag_eph = 0;
		int abn_cnt = 0;
		int abnormal = 1;
		Uint16  datalen;
		Uint8 bufferlen[2];



		/****************************************************************************************************************************************/
		/****************************************************************自遥测帧****************************************************************/
		/****************************************************************************************************************************************/

		//帧头判别
		Uint8* Infodata2Crc;
		Infodata2Crc = new Uint8[sizeof(Gnss3SelfInfo) + 5];//[2+1+2+36]接收机ID+帧类型+数据体长度+数据体DATA

		while (1)
		{
			if (buffer[0] == RcvHeader[0] && buffer[1] == RcvHeader[1] && buffer[2] == RcvHeader[2] && buffer[3] == RcvHeader[3] && (buffer[6] == SelfInfoID||buffer[6] == SelfPosID))
			{
				if(buffer[6] == SelfInfoID) flag_SelfInfo = 1;
				else if (buffer[6] == SelfPosID) flag_SelfPos = 1;
				abnormal = 1;
				break;
			}
			else if (abnormal == 1)// only record first abnormal time-point
			{
				abnormal = 0;
				abn_cnt++;
				abnormal_epoch << timemark << " " << endl;
				infile >> hex >> datatemp;
				total_length++;
				for (i = 0; i < header_size - 1; i++) buffer[i] = buffer[i + 1];
				buffer[6] = datatemp;
			}
			else
			{
				abn_cnt++;
				infile >> hex >> datatemp;
				total_length++;
				for (i = 0; i < header_size - 1; i++) buffer[i] = buffer[i + 1];
				buffer[6] = datatemp;
			}
		}
		printf("progress %.3f%%\r\n", total_length / ByteLen);


		if (flag_SelfInfo == 1)
		{
			//数据长度 
			for (j = 0; j < data_byte_size; j++)
			{
				infile >> hex >> datatemp;
				bufferlen[j] = datatemp;
				total_length++;
			}
			datalen = bufferlen[0] + (bufferlen[data_byte_size - 1] << 8);

			// 取数据 crc校验 
			Infodata2Crc[0] = 0x00;
			Infodata2Crc[1] = 0x00;
			Infodata2Crc[2] = 0x06;
			for (j = 0; j < 2; j++) Infodata2Crc[3 + j] = bufferlen[j];

			//获取自遥测帧数据
			Uint8* databuffer;
			databuffer = new Uint8[datalen];
			for (j = 0; j < datalen; j++)
			{
				infile >> hex >> datatemp;
				databuffer[j] = datatemp;
				total_length++;
				Infodata2Crc[j + 5] = datatemp;//取数据  做crc校验

			}
			crc = CalculateBlockCRC32((sizeof(Gnss3SelfInfo) + 5), Infodata2Crc);
			delete[]  Infodata2Crc;

			SelfInfo = (Gnss3SelfInfo*)(databuffer);

			info << dec << (int)SelfInfo->L1_PLL_Config1 << " " << (int)SelfInfo->L2_PLL_Config1 << " "
				<< SelfInfo->L1AGC << " " << SelfInfo->L2AGC << " "
				<< (int)SelfInfo->L1_Acq_Prn1_8 << " " << (int)SelfInfo->L1_Acq_Prn9_16 << " " << (int)SelfInfo->L1_Acq_Prn17_24 << " " << (int)SelfInfo->L1_Acq_Prn25_32 << " " << (int)SelfInfo->L1_Acq_Prn33_40 << " "
				<< (int)SelfInfo->L2_Acq_Prn1_8 << " " << (int)SelfInfo->L2_Acq_Prn9_16 << " " << (int)SelfInfo->L2_Acq_Prn17_24 << " " << (int)SelfInfo->L2_Acq_Prn25_32 << " " << (int)SelfInfo->L2_Acq_Prn33_40 << " "
				<< (int)SelfInfo->chan_trackflag1_8 << " " << (int)SelfInfo->chan_trackflag9_16 << " " << (int)SelfInfo->chan_trackflag17_24
				<< endl;


			//获取自遥测帧尾 
			Uint8* tailbuffer;
			tailbuffer = new Uint8[sizeof(tailStruct)];
			for (j = 0; j < sizeof(tailStruct); j++)
			{
				infile >> hex >> datatemp;
				tailbuffer[j] = datatemp;
				total_length++;
			}
			tailofSelfinfo = (tailStruct*)(tailbuffer);

			//crc校验
			if (crc != tailofSelfinfo->crc) infocrccheck << 0 << endl;
			else infocrccheck << 1 << endl;

			delete[] databuffer;
			delete[] tailbuffer;
			flag_SelfInfo = 0;
			crc = 0;
		}
		/****************************************************************************************************************************************/
		/****************************************************************自定位帧****************************************************************/
		/****************************************************************************************************************************************/
		if (!flag_SelfPos) {
			for (i = 0; i < header_size; i++)
			{
				infile >> hex >> datatemp;
				buffer[i] = datatemp;
				total_length++;
			}

			//帧头判别
			if (buffer[0] == RcvHeader[0] && buffer[1] == RcvHeader[1] && buffer[2] == RcvHeader[2] && buffer[3] == RcvHeader[3] && buffer[6] == SelfPosID) {
				flag_SelfPos = 1;
			}
			else flag_SelfPos = 0;
		}
		static bool headerFlag = false;
		if (flag_SelfPos == 1)
		{
			for (j = 0; j < data_byte_size; j++)
			{
				infile >> hex >> datatemp;
				bufferlen[j] = datatemp;
				total_length++;
			}
			datalen = bufferlen[0] + (bufferlen[data_byte_size - 1] << 8);

			Uint8* Posdata2Crc;
			Posdata2Crc = new Uint8[datalen + 5];
			// 取数据 crc校验 
			Posdata2Crc[0] = 0x00;
			Posdata2Crc[1] = 0x00;
			Posdata2Crc[2] = 0x00;
			for (j = 0; j < 2; j++) Posdata2Crc[3 + j] = bufferlen[j];

			//获取自定位帧数据
			Uint8* databuffer;
			databuffer = new Uint8[datalen];

			for (j = 0; j < datalen; j++)
			{
				infile >> hex >> datatemp;
				databuffer[j] = datatemp;
				Posdata2Crc[j + 5] = datatemp;//取数据  做crc校验
				total_length++;

			}
			crc = CalculateBlockCRC32((datalen + 5), Posdata2Crc);
			delete[]  Posdata2Crc;

			PosStruct* SelfPosition;
			SelfPosition = (PosStruct*)(databuffer);
			chanstate* channel;
			mode = (datalen > SMPosLen)?2:((SelfPosition->GNSS3CoorType)?1:0);// GPS:0;BD:1;MIX:2

			if ((int)(SelfPosition->GNSS3Pos_X) != 0 && (int)SelfPosition->GNSS3Year != 0)  //print control
			{
				PrintControlFlag = 1;
				timemark += 1;

				pos << timemark << " " << (int)SelfPosition->GNSS3ChannelNum << " "
					<< (int)SelfPosition->GNSS3Year << " " << (int)SelfPosition->GNSS3Month << " " << (int)SelfPosition->GNSS3Day << " "
					<< SelfPosition->GNSS3DaySec << " " << (int)SelfPosition->GNSS3TimeType << " "
					<< SelfPosition->GNSS3Pos_X << " " << SelfPosition->GNSS3Pos_Y << " " << SelfPosition->GNSS3Pos_Z << " "
					<< SelfPosition->GNSS3Vel_X << " " << SelfPosition->GNSS3Vel_Y << " " << SelfPosition->GNSS3Vel_Z << " "
					<< (int)SelfPosition->GNSS3PDOP << " " << SelfPosition->GNSS3ClkBias << " ";
				if (mode != 2) {
					for (i = 0; i < 24; i++) {
						channel = (chanstate*)(databuffer+sizeof(PosStruct)+i*sizeof(chanstate));
						pos << (int)channel->CN << " ";
					}
				}
				else {
					for (i = 0; i < 48; i++) {
						channel = (chanstate*)(databuffer+sizeof(PosStruct)+i*sizeof(chanstate));
						pos << (int)channel->CN << " ";
					}
				}
				pos << endl;
				double ep[6];
				ep[0] = (double)SelfPosition->GNSS3Year;
				ep[1] = (double)SelfPosition->GNSS3Month;
				ep[2] = (double)SelfPosition->GNSS3Day;
				ep[3] = (double)(SelfPosition->GNSS3DaySec / 10000 / 3600);
				ep[4] = (int)(((double)(SelfPosition->GNSS3DaySec) / 10000 - ep[3] * 3600) / 60);
				ep[5] = (double)(SelfPosition->GNSS3DaySec) / 10000 - ep[3] * 3600 - (double)ep[4] * 60;

				gtime_t time1;
				int week;
				double tow;

				time1 = epoch2time(ep);
				tow = time2gpst(time1, &week);
				tow = tow * 1000;
				compareGPST << timemark << " " << (int)week << " " << (int)tow << " " << endl;//自定位帧GPST输出
				if (!headerFlag) {
					headerFlag = true;
					if (mode == 0) {
						obstL1.open(a + "obsL1.txt");
						obstL2.open(a + "obsL2.txt");
						CHK_obstL1.open(a + "CHK_obsL1.txt");
						CHK_obstL2.open(a + "CHK_obsL2.txt");
					}
					else if (mode == 1) {
						obstB1.open(a + "obsB1.txt");
						obstB3.open(a + "obsB3.txt");
						CHK_obstB1.open(a + "CHK_obsB1.txt");
						CHK_obstB3.open(a + "CHK_obsB3.txt");
					}
					else {
						obstL1.open(a + "obsL1.txt");
						obstL2.open(a + "obsL2.txt");
						obstB1.open(a + "obsB1.txt");
						obstB3.open(a + "obsB3.txt");
						CHK_obstL1.open(a + "CHK_obsL1.txt");
						CHK_obstL2.open(a + "CHK_obsL2.txt");
						CHK_obstB1.open(a + "CHK_obsB1.txt");
						CHK_obstB3.open(a + "CHK_obsB3.txt");
					}
					dayofYear = time2doy(epoch2time(ep));
					ephFile = "ZJUM"+std::to_string(dayofYear) + "0."+ std::to_string((int)ep[0] % 100)+"N";
					obsFile = "ZJUM" + std::to_string(dayofYear) + "0." + std::to_string((int)ep[0] % 100) + "O";
					ephStream.open(ephFile);
					obsStream.open(obsFile);
					CHK_obsStream.open("CHK_" + obsFile);
					if (ephStream.is_open()) ephHeader(ephStream, mode);//convert to GPST or not
					if (obsStream.is_open()) obsHeader(obsStream, mode, bdtFlag);
					if (CHK_obsStream.is_open()) obsHeader(CHK_obsStream, mode, bdtFlag);
				}
				
			}

			//获取crc 
			Uint8* tailbuffer;
			tailbuffer = new Uint8[sizeof(tailStruct)];
			for (j = 0; j < sizeof(tailStruct); j++)
			{
				infile >> hex >> datatemp;
				tailbuffer[j] = datatemp;
				total_length++;
			}
			tailofSelfPos = (tailStruct*)(tailbuffer);

			//crc校验
			if (crc != tailofSelfPos->crc) poscrccheck << 0 << endl;
			else poscrccheck << 1 << endl;

			crc = 0;
			delete[] databuffer;
			delete[] tailbuffer;
			flag_SelfPos = 0;
		}
		/****************************************************************************************************************************************/
		/****************************************************************测量元素帧**************************************************************/
		/****************************************************************************************************************************************/
		for (i = 0; i < header_size; i++)
		{
			infile >> hex >> datatemp;
			buffer[i] = datatemp;
			total_length++;
		}
		//帧头判别
		if (buffer[0] == RcvHeader[0] && buffer[1] == RcvHeader[1] && buffer[2] == RcvHeader[2] && buffer[3] == RcvHeader[3] && buffer[6] == ObsID) {
				flag_obs = 1;
		}
		else flag_obs = 0;

		if (flag_obs == 1)
		{
			for (j = 0; j < data_byte_size; j++)
			{
				infile >> hex >> datatemp;
				bufferlen[j] = datatemp;
				total_length++;
			}
			datalen = bufferlen[0] + (bufferlen[data_byte_size - 1] << 8);

			Uint8* obsdata2Crc;
			obsdata2Crc = new Uint8[datalen + 5];//[2+1+2+36]
			// 取数据 crc校验
			obsdata2Crc[0] = 0x00;
			obsdata2Crc[1] = 0x00;
			obsdata2Crc[2] = 0x01;
			for (j = 0; j < 2; j++) obsdata2Crc[3 + j] = bufferlen[j];

			//获取 测量元素帧数据
			Uint8* databuffer;
			databuffer = new Uint8[datalen];

			for (j = 0; j < datalen; j++)
			{
				infile >> hex >> datatemp;
				databuffer[j] = datatemp;
				obsdata2Crc[j + 5] = datatemp;
				total_length++;
			}

			crc = CalculateBlockCRC32((datalen + 5), obsdata2Crc);
			delete[]  obsdata2Crc;

			obsframe_t* obs,*obsL2,*obsB1,*obsB3;//databuffer[0] is the frameNum
			obs = (obsframe_t*)(databuffer+1);
			if (PrintControlFlag == 1)  //print control
			{
				int week = 0;
				double sec = 0;
				gtime_t utctime;
				int nobsL1 = 0, nobsL2 = 0,nobsB1 = 0,nobsB3 = 0;
				int nobsL1past = 0, nobsL2past = 0,nobsB1past = 0,nobsB3past = 0;
				double DT = 0.0;
				GPS_TIME = (obs->time2 * (2 ^ 32) + obs->time1) / (10 ^ 7);
				int LLI = 0;
				int SSI = 0;
				memcpy(ephobspast, ephobs, sizeof(double) * 6);
				obstimepast = obstime;
				if (obs->time1) {
					week = obs->time1;
					sec = double(obs->time2) / 10000000;///double(10000000);
					obstime = (mode)?bdt2time(week-1356, sec+14):gpst2time(week, sec);
					if (bdtFlag) obstime = timeadd(obstime, -14);
					time2epoch(obstime, ephobs);
					/*utctime = gpst2utc(gpstime);
					time2epoch(utctime, ep);*/
				}
				memcpy(satobspast,satobs,sizeof(obschannel_t)*4*BD2PrnNum);
				memset(satobs, 0x00, sizeof(obschannel_t) * 4 * BD2PrnNum);
				if (mode == 2) {
					obsB1 = (obsframe_t*)(databuffer+1+1*sizeof(obsframe_t));
					obsL2 = (obsframe_t*)(databuffer+1+2*sizeof(obsframe_t));
					obsB3 = (obsframe_t*)(databuffer+1+3*sizeof(obsframe_t));
					for (j = 0; j < 12; j++)
					{
						if (obs->obschannel[j].prn > 0 && obs->obschannel[j].CPseudorange != 0 && obs->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsL1++;
							if (satobspast[0][obs->obschannel[j].prn - 1].prn) nobsL1past++;
							satobs[0][obs->obschannel[j].prn - 1] = obs->obschannel[j];
						}
						obsB1->obschannel[j].prn -= 200;
						if (obsB1->obschannel[j].prn > 0 && obsB1->obschannel[j].CPseudorange != 0 && obsB1->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsB1++;
							if(satobspast[2][obsB1->obschannel[j].prn - 1].prn) nobsB1past++;
							satobs[2][obsB1->obschannel[j].prn - 1] = obsB1->obschannel[j];
						}
						if (obsL2->obschannel[j].prn > 0 && obsL2->obschannel[j].CPseudorange != 0 && obsL2->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsL2++;
							if(satobspast[1][obsL2->obschannel[j].prn - 1].prn) nobsL2past++;
							satobs[1][obsL2->obschannel[j].prn - 1] = obsL2->obschannel[j];
						}
						obsB3->obschannel[j].prn -= 200;
						if (obsB3->obschannel[j].prn > 0 && obsB3->obschannel[j].CPseudorange != 0 && obsB3->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsB3++;
							if(satobspast[3][obsB3->obschannel[j].prn - 1].prn) nobsB3past++;
							satobs[3][obsB3->obschannel[j].prn - 1] = obsB3->obschannel[j];
						}
					}
				}
				else if (mode == 0) {
					obsL2 = (obsframe_t*)(databuffer+1+1*sizeof(obsframe_t));
					for (j = 0; j < 12; j++)
					{
						if (obs->obschannel[j].prn > 0 && obs->obschannel[j].prn <= GpsPrnNum && obs->obschannel[j].CPseudorange != 0 && obs->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsL1++;
							if(satobspast[0][obs->obschannel[j].prn - 1].prn) nobsL1past++;
							satobs[0][obs->obschannel[j].prn - 1] = obs->obschannel[j];
						}
						if (obsL2->obschannel[j].prn > 0 && obsL2->obschannel[j].prn <= GpsPrnNum && obsL2->obschannel[j].CPseudorange != 0 && obsL2->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsL2++;
							if(satobspast[1][obsL2->obschannel[j].prn - 1].prn) nobsL2past++;
							satobs[1][obsL2->obschannel[j].prn - 1] = obsL2->obschannel[j];
						}
					}
				}
				else if(mode == 1){
					obsB3 = (obsframe_t*)(databuffer+1+1*sizeof(obsframe_t));
					for (j = 0; j < 12; j++)
					{
						if (obs->obschannel[j].prn > 0 && obs->obschannel[j].CPseudorange != 0 && obs->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsB1++;
							if(satobspast[0][obs->obschannel[j].prn - 1].prn) nobsB1past++;
							satobs[0][obs->obschannel[j].prn - 1] = obs->obschannel[j];

						}
						if (obsB3->obschannel[j].prn > 0 && obsB3->obschannel[j].CPseudorange != 0 && obsB3->obschannel[j].carrierPhase != 0x7fffffffffffffff) {
							nobsB3++;
							if(satobspast[1][obsB3->obschannel[j].prn - 1].prn) nobsB3past++;
							satobs[1][obsB3->obschannel[j].prn - 1] = obsB3->obschannel[j];
						}
					}
			}

				if(obsStream.is_open()) 
					obsStream << setfill('0')<< "> " << setw(4) << (int)ephobs[0] << " " << setw(2) << (int)ephobs[1] << " " << setw(2) << (int)ephobs[2]
					<< " " << setw(2) << (int)ephobs[3] << " " << setw(2) << (int)ephobs[4] << " " << fixed << setw(10) << setprecision(7) << (double)ephobs[5] << setfill(' ') << "  0" << setw(3) << (nobsL1+nobsB1) << setw(6) << " " << setw(15) << setprecision(12) << DT << endl;
				if(CHK_obsStream.is_open()&&ephobspast[0])
					CHK_obsStream << setfill('0')<< "> " << setw(4) << (int)ephobspast[0] << " " << setw(2) << (int)ephobspast[1] << " " << setw(2) << (int)ephobspast[2]
					<< " " << setw(2) << (int)ephobspast[3] << " " << setw(2) << (int)ephobspast[4] << " " << fixed << setw(10) << setprecision(7) << (double)ephobspast[5] << setfill(' ') << "  0" << setw(3) << (nobsL1past+nobsB1past) << setw(6) << " " << setw(15) << setprecision(12) << DT << endl;
				
				for (j = 0; j < BD2PrnNum; j++)
				{
					if (!mode) {
						if (satobs[0][j].prn) {
							obstL1 << timemark << " "
								<< nobsL1 << " " << satobs[0][j].prn << " " << satobs[0][j].CPseudorange << " "
								<< satobs[0][j].carrierPhase << " " << satobs[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if(satobspast[0][j].prn)
								CHK_obstL1 << timemark-1 << " "
									<< nobsL1past << " " << satobspast[0][j].prn << " " << satobspast[0][j].CPseudorange << " "
									<< satobspast[0][j].carrierPhase << " " << satobspast[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
						}
						if (satobs[1][j].prn) {
							obstL2 << timemark << " "
								<< nobsL2 << " " << satobs[1][j].prn << " " << satobs[1][j].CPseudorange << " "
								<< satobs[1][j].carrierPhase << " " << satobs[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if(satobspast[1][j].prn)
								CHK_obstL2 << timemark-1 << " "
									<< nobsL2past << " " << satobspast[1][j].prn << " " << satobspast[1][j].CPseudorange << " "
									<< satobspast[1][j].carrierPhase << " " << satobspast[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
						}
					}
					else if(mode == 1) {
						if (satobs[0][j].prn) {
							obstB1 << timemark << " "
								<< nobsB1 << " " << satobs[0][j].prn << " " << satobs[0][j].CPseudorange << " "
								<< satobs[0][j].carrierPhase << " " << satobs[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							satobspast[0][j].carrierPhase = satobspast[0][j].carrierPhase + 24.005 / 8.0 / lam * obstimepast.time*1000;
							if(satobspast[0][j].prn)
								CHK_obstB1 << timemark-1 << " "
									<< nobsB1past << " " << satobspast[0][j].prn << " " << satobspast[0][j].CPseudorange << " "
									<< satobspast[0][j].carrierPhase << " " << satobspast[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
						}
						if (satobs[1][j].prn) {
							obstB3 << timemark << " "
								<< nobsB3 << " " << satobs[1][j].prn << " " << satobs[1][j].CPseudorange << " "
								<< satobs[1][j].carrierPhase << " " << satobs[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if(satobspast[1][j].prn)
								CHK_obstB3 << timemark-1 << " "
									<< nobsL2past << " " << satobspast[1][j].prn << " " << satobspast[1][j].CPseudorange << " "
									<< satobspast[1][j].carrierPhase << " " << satobspast[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
						}
					}
					if (satobs[0][j].prn <= 0) continue;
					char obsType = (mode == 0 || mode == 2) ? (char)'G' : (char)'C';
					if (obsStream.is_open())
						obsStream << obsType << setfill('0') << setw(2) << satobs[0][j].prn
						<< setfill(' ') << setw(14) << setprecision(3) << (double)satobs[0][j].CPseudorange / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobs[1][j].CPseudorange / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << fmod((double)satobs[0][j].carrierPhase / 1000,1E9) << LLI << SSI
						<< setw(14) << setprecision(3) << fmod((double)satobs[1][j].carrierPhase / 1000,1E9) << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobs[0][j].Doppler / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobs[1][j].Doppler / 100  << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobs[0][j].CN / 4 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobs[1][j].CN / 4  << LLI << SSI << endl;
					if (CHK_obsStream.is_open()&&ephobspast[0]&&satobspast[0][j].prn)
						CHK_obsStream << obsType << setfill('0') << setw(2) << satobspast[0][j].prn
						<< setfill(' ') << setw(14) << setprecision(3) << (double)satobspast[0][j].CPseudorange / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobspast[1][j].CPseudorange / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << fmod((double)satobspast[0][j].carrierPhase / 1000,1E9) << LLI << SSI
						<< setw(14) << setprecision(3) << fmod((double)satobspast[1][j].carrierPhase / 1000,1E9) << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobspast[0][j].Doppler / 100 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobspast[1][j].Doppler / 100  << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobspast[0][j].CN / 4 << LLI << SSI
						<< setw(14) << setprecision(3) << (double)satobspast[1][j].CN / 4  << LLI << SSI << endl;
				}
				if (mode == 2){
					for (j = 0; j < BD2PrnNum; j++)	{
						if (satobs[0][j].prn) {
							obstL1 << timemark << " "
								<< nobsL1 << " " << satobs[0][j].prn << " " << satobs[0][j].CPseudorange << " "
								<< satobs[0][j].carrierPhase << " " << satobs[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if(satobspast[0][j].prn)
								CHK_obstL1 << timemark-1 << " "
									<< nobsL1past << " " << satobspast[0][j].prn << " " << satobspast[0][j].CPseudorange << " "
									<< satobspast[0][j].carrierPhase << " " << satobspast[0][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
						}
						if (satobs[1][j].prn) {
							obstL2 << timemark << " "
								<< nobsL2 << " " << satobs[1][j].prn << " " << satobs[1][j].CPseudorange << " "
								<< satobs[1][j].carrierPhase << " " << satobs[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if (satobspast[1][j].prn) {
								CHK_obstL2 << timemark-1 << " "
									<< nobsL2past << " " << satobspast[1][j].prn << " " << satobspast[1][j].CPseudorange << " "
									<< satobspast[1][j].carrierPhase << " " << satobspast[1][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
							}
						}
						if (satobs[2][j].prn) {
							obstB1 << timemark << " "
								<< nobsB1 << " " << satobs[2][j].prn << " " << satobs[2][j].CPseudorange << " "
								<< satobs[2][j].carrierPhase << " " << satobs[2][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							satobspast[2][j].carrierPhase = satobspast[2][j].carrierPhase + 24.005 / 8.0 / lam * obstimepast.time*1000;
							if (satobspast[2][j].prn) {
								CHK_obstB1 << timemark-1 << " "
									<< nobsB1past << " " << satobspast[2][j].prn << " " << satobspast[2][j].CPseudorange << " "
									<< satobspast[2][j].carrierPhase << " " << satobspast[2][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
							}
						}
						if (satobs[3][j].prn) {
							obstB3 << timemark << " "
								<< nobsB3 << " " << satobs[3][j].prn << " " << satobs[3][j].CPseudorange << " "
								<< satobs[3][j].carrierPhase << " " << satobs[3][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
								<< endl;
							if (satobspast[3][j].prn) {
								CHK_obstB3 << timemark-1 << " "
									<< nobsB3past << " " << satobspast[3][j].prn << " " << satobspast[3][j].CPseudorange << " "
									<< satobspast[3][j].carrierPhase << " " << satobspast[3][j].Doppler << " "//	<<(int)obs->obschannel[j].CN
									<< endl;
							}
						}
						if (satobs[2][j].prn <= 0) continue;
						char obsType = (char)'C';
						if (obsStream.is_open())
							obsStream << obsType << setfill('0') << setw(2) << satobs[2][j].prn
							<< setfill(' ') << setw(14) << setprecision(3) << (double)satobs[2][j].CPseudorange / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobs[3][j].CPseudorange / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << fmod((double)satobs[2][j].carrierPhase / 1000,1E9) << LLI << SSI
							<< setw(14) << setprecision(3) << fmod((double)satobs[3][j].carrierPhase / 1000,1E9) << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobs[2][j].Doppler / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobs[3][j].Doppler / 100  << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobs[2][j].CN / 4 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobs[3][j].CN / 4  << LLI << SSI << endl;
						if (CHK_obsStream.is_open()&&ephobspast[0]&&satobspast[2][j].prn)
							CHK_obsStream << obsType << setfill('0') << setw(2) << satobspast[2][j].prn
							<< setfill(' ') << setw(14) << setprecision(3) << (double)satobspast[2][j].CPseudorange / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobspast[3][j].CPseudorange / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << fmod((double)satobspast[2][j].carrierPhase / 1000,1E9) << LLI << SSI
							<< setw(14) << setprecision(3) << fmod((double)satobspast[3][j].carrierPhase / 1000,1E9) << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobspast[2][j].Doppler / 100 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobspast[3][j].Doppler / 100  << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobspast[2][j].CN / 4 << LLI << SSI
							<< setw(14) << setprecision(3) << (double)satobspast[3][j].CN / 4  << LLI << SSI << endl;
					}
				}
			}
			Uint8* tailbuffer;
			tailbuffer = new Uint8[sizeof(tailStruct)];
			for (j = 0; j < sizeof(tailStruct); j++)
			{
				infile >> hex >> datatemp;
				tailbuffer[j] = datatemp;
				total_length++;
			}

			tailofobs = (tailStruct*)(tailbuffer);

			//crc校验
			if (crc != tailofobs->crc) obscrccheck << 0 << endl;
			else obscrccheck << 1 << endl;

			crc = 0;
			delete[] databuffer;
			delete[] tailbuffer;
			flag_obs = 0;
		}
		/****************************************************************************************************************************************/
		/****************************************************************导航电文帧**************************************************************/
		/****************************************************************************************************************************************/

		for (i = 0; i < header_size; i++)
		{
			infile >> hex >> datatemp;
			buffer[i] = datatemp;
			total_length++;
		}
		Uint8 ephcnt = 0;
		while (buffer[0] == RcvHeader[0] && buffer[1] == RcvHeader[1] && buffer[2] == RcvHeader[2] && buffer[3] == RcvHeader[3] && buffer[6] == EphID)
		{
			ephcnt++;
			Uint8 *databuffer;
			databuffer = new Uint8[62];
			for (i = 0; i < 62; i++)
			{
				infile >> hex >> datatemp;
				databuffer[i] = datatemp;
				total_length++;
			}
			eph = (GNSS3eph_t*)(databuffer);
			if (ephcnt > 12&&eph->prn) eph->prn = eph->prn - 200;

			if ((eph->prn>0) && (eph->prn<BD2PrnNum)&& eph->year!= 0)
			{
				if ((mode == 0)||(mode == 2 && ephcnt <= 12))//坐标系0为GPS,2为BD
				{
					word_gps[0] = (eph->word[0] & 0x3FFFFFC0) >> 6;
					for (i = 1; i < 10; i++)
					{
						if (eph->word[i - 1] & 0x01)
						{
							word_gps[i] = (((eph->word[i] & 0x3FFFFFC0) >> 6) ^ 0x00FFFFFF) & 0x00FFFFFF;//取反
						}
						else
						{
							word_gps[i] = (((eph->word[i] & 0x3FFFFFC0) >> 6) ^ 0x00000000) & 0x00FFFFFF;//不变
						}
					}

					GpsEphmeris_LNav[eph->prn-1].idofsubframe = (word_gps[1] & 0x0000001C) >> 2;

					GpsTmpEphmeris_LNav[eph->prn-1].idofsubframe = GpsEphmeris_LNav[eph->prn-1].idofsubframe;
					GpsTmpEphmeris_LNav[eph->prn-1].HOWtime = (long)((word_gps[1] & 0x00FFFF80) >> 7);
					switch (GpsEphmeris_LNav[eph->prn-1].idofsubframe)
					{
					case 1:
					case 2:
					case 3:
						Gps_LNAV_Eph(word_gps, &GpsTmpEphmeris_LNav[eph->prn-1], &GpsEphmeris_LNav[eph->prn-1]);
						break;
					case 4:
					case 5:
						GpsLNAVAlmDisassemble(word_gps, &GpsAlm[eph->prn-1], GpsEphmeris_LNav[eph->prn-1].idofsubframe);
						break;
					default:break;
					}
				}
				else if ((mode == 1)||(mode == 2 && ephcnt > 12))
				{
					BD2Ephmeris_B1[eph->prn-1].idofsubframe = (eph->word[0] & 0x00007000) >> 12;
					BD2TmpEphmeris_B1[eph->prn-1].idofsubframe = BD2Ephmeris_B1[eph->prn-1].idofsubframe;
					if (eph->prn > 5)
					{
						switch (BD2Ephmeris_B1[eph->prn-1].idofsubframe)
						{
						case 1:
						case 2:
						case 3:
							BD2_Eph_D1(eph->word, &BD2TmpEphmeris_B1[eph->prn-1], &BD2Ephmeris_B1[eph->prn-1]);
							break;
						default:break;
						}
					}
					else if (eph->prn <= 5)
					{
						if (BD2Ephmeris_B1[eph->prn-1].idofsubframe == 1)
						{
							BD2_Eph_D2(eph->word, &BD2TmpEphmeris_B1[eph->prn-1], &BD2Ephmeris_B1[eph->prn-1]);
						}
					}

				}
			}
			//if ((BD2TmpEphmeris_B1[eph->prn-1].idofsubframe == 3 && BD2TmpEphmeris_B1[eph->prn-1].beSVpos == true) 
			//	|| (GpsTmpEphmeris_LNav[eph->prn-1].idofsubframe == 3 && GpsTmpEphmeris_LNav[eph->prn-1].beSVpos == true))
			{
				if (eph->year == 0||eph->prn<=0||eph->prn>BD2PrnNum)
				{
					if (eph->year == 0) cout << "ephdata is still invalid" << endl;
				}
				else if (((mode == 0)||(mode == 2 && ephcnt <= 12))&&(GpsTmpEphmeris_LNav[eph->prn-1].idofsubframe == 3 && GpsTmpEphmeris_LNav[eph->prn-1].beSVpos == true))
				{
					//导航电文内容
					double ep[6];
					char scibuf0[20], scibuf1[20], scibuf2[20], scibuf3[20];
					memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].af0, 13), 20);
					memcpy(scibuf1, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].af1, 13), 20);
					memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].af2, 13), 20);
					time2epoch(gpst2time(GpsTmpEphmeris_LNav[eph->prn-1].WeekNum,GpsTmpEphmeris_LNav[eph->prn-1].Toc),ep);
					if (ephStream.is_open()&& TocBuf[eph->prn-1]!= GpsTmpEphmeris_LNav[eph->prn-1].Toc)
					{
						//nav_flag[eph->prn-1] = 1;
						TocBuf[eph->prn - 1] = GpsTmpEphmeris_LNav[eph->prn-1].Toc;
						ephStream  << "G" << setw(2) << setfill('0') << eph->prn
							<< " " << setw(4) << (int)ep[0]
							<< " " << setw(2) << (int)ep[1]
							<< " " << setw(2) << (int)ep[2]
							<< " " << setw(2) << ep[3]
							<< " " << setw(2) << ep[4]
							<< " " << setw(2) << ep[5]
							<< scibuf0
							<< scibuf1
							<< scibuf2
							<< setfill(' ') << endl;

						memcpy(scibuf0, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].IODE[0], 13), 20);
						memcpy(scibuf1, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Crs, 13), 20);
						memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].dn, 13), 20);
						memcpy(scibuf3, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].M0, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Cuc, 13), 20);
						memcpy(scibuf1, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].ecc, 13), 20);
						memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Cus, 13), 20);
						memcpy(scibuf3, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Asqrt, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Toe, 13), 20);
						memcpy(scibuf1, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Cic, 13), 20);
						memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].OMEGA0, 13), 20);
						memcpy(scibuf3, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Cis, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].i0, 13), 20);
						memcpy(scibuf1, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Crc, 13), 20);
						memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].w, 13), 20);
						memcpy(scibuf3, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].OMEGAdot, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].idot, 13), 20);
						memcpy(scibuf1, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].CodeOnL2, 13), 20);
						memcpy(scibuf2, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].WeekNum, 13), 20);
						memcpy(scibuf3, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].haveL2Message, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].accuracy, 13), 20);
						memcpy(scibuf1, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].SVhealth, 13), 20);
						memcpy(scibuf2, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Tgd, 13), 20);
						memcpy(scibuf3, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].IODC, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(GpsTmpEphmeris_LNav[eph->prn-1].Toe, 13), 20);
						memcpy(scibuf1, scientific_h((double)GpsTmpEphmeris_LNav[eph->prn-1].fit, 13), 20);
						memcpy(scibuf2, scientific_h((double)0, 13), 20);
						memcpy(scibuf3, scientific_h((double)0, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;


						if (GpsTmpEphmeris_LNav[eph->prn-1].Asqrt < 2550)
						{
							cout << "GPS earth radical error" << endl;
						}

					}
				}
				else if (((mode == 1)||(mode == 2 && ephcnt > 12))&&(BD2TmpEphmeris_B1[eph->prn-1].idofsubframe == 3 && BD2TmpEphmeris_B1[eph->prn-1].beSVpos == true) )
				{
					//导航电文内容
					double ep[6];
					char scibuf0[20], scibuf1[20], scibuf2[20], scibuf3[20];
					memcpy(scibuf0, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].a0, 13), 20);
					memcpy(scibuf1, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].a1, 13), 20);
					memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].a2, 13), 20);
					time2epoch(bdt2time(BD2TmpEphmeris_B1[eph->prn-1].WeekNum,BD2TmpEphmeris_B1[eph->prn-1].Toc),ep);
					if (ephStream.is_open() && TocBuf[eph->prn - 1+GpsPrnNum] != BD2TmpEphmeris_B1[eph->prn-1].Toc)
					{
						//nav_flag[eph->prn-1] = 1;
						TocBuf[eph->prn - 1+GpsPrnNum] = BD2TmpEphmeris_B1[eph->prn-1].Toc;
						ephStream  << "C" << setw(2) << setfill('0') << eph->prn
							<< " " << setw(4) << (int)ep[0]
							<< " " << setw(2) << (int)ep[1]
							<< " " << setw(2) << (int)ep[2]
							<< " " << setw(2) << ep[3]
							<< " " << setw(2) << ep[4]
							<< " " << setw(2) << ep[5]
							<< scibuf0
							<< scibuf1
							<< scibuf2
							<< setfill(' ') << endl;

						memcpy(scibuf0, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].AODE, 13), 20);
						memcpy(scibuf1, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Crs, 13), 20);
						memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].dn, 13), 20);
						memcpy(scibuf3, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].M0, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Cuc, 13), 20);
						memcpy(scibuf1, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].ecc, 13), 20);
						memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Cus, 13), 20);
						memcpy(scibuf3, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Asqrt, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].Toe, 13), 20);
						memcpy(scibuf1, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Cic, 13), 20);
						memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].OMEGA0, 13), 20);
						memcpy(scibuf3, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Cis, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].i0, 13), 20);
						memcpy(scibuf1, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Crc, 13), 20);
						memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].w, 13), 20);
						memcpy(scibuf3, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].OMEGAdot, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].idot, 13), 20);
						memcpy(scibuf1, scientific_h((double)0, 13), 20);
						memcpy(scibuf2, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].WeekNum, 13), 20);
						memcpy(scibuf3, scientific_h((double)0, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].URAI, 13), 20);
						memcpy(scibuf1, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].SatH1, 13), 20);
						memcpy(scibuf2, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Tgd1, 13), 20);
						memcpy(scibuf3, scientific_h(BD2TmpEphmeris_B1[eph->prn-1].Tgd2, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						memcpy(scibuf0, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].Toe, 13), 20);
						memcpy(scibuf1, scientific_h((double)BD2TmpEphmeris_B1[eph->prn-1].AODC, 13), 20);
						memcpy(scibuf2, scientific_h((double)0, 13), 20);
						memcpy(scibuf3, scientific_h((double)0, 13), 20);
						ephStream << setw(4) << " " << scibuf0 << scibuf1 << scibuf2 << scibuf3 << endl;

						if (BD2TmpEphmeris_B1[eph->prn-1].Asqrt < 2550)
						{
							cout << "BD earth radical error" << endl;
						}

					}

				}
			}

			delete[] databuffer;
			//取下一包帧头用来判断是否再次进入电文解包
			for (i = 0; i < header_size; i++)
			{
				infile >> hex >> datatemp;
				buffer[i] = datatemp;
				total_length++;
			}
		}
	}

	info.close();
	pos.close();
	obstL1.close();
	obstL2.close();
	obstB1.close();
	obstB3.close();
	if (ephStream.is_open()) ephStream.close();
	if (obsStream.is_open()) obsStream.close();
	infocrccheck.close();
	poscrccheck.close();
	obscrccheck.close();
	ephcrccheck.close();
	compareGPST.close();
	abnormal_epoch.close();

	CHK_obstL1.close();
	CHK_obstL2.close();
	CHK_obstB1.close();
	CHK_obstB3.close();
	CHK_obsStream.close();
	return 1;
}
